home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C Templates / Common.c < prev    next >
Text File  |  1995-01-29  |  8KB  |  278 lines

  1. $$Message User Common, u:common$Prototype.name$.h
  2. $$File u:common$Prototype.name$.h
  3. /*  common$Prototype.name$                         Common */
  4. /*  $CopyRight$ */
  5.  
  6. /* 
  7.     File name:  common$Prototype.name$.h   
  8.     Function:  Common variables for program specific code.
  9.     History: $Date$ Original by $Author$
  10.  
  11.    */
  12.  
  13. /* ======================================================= */
  14. /* ======================================================= */
  15.  
  16. /* NOTE : FormatRevision MUST be first in the record, and always a short */
  17. typedef struct PrefsRec{                        /* Preferences Record definition */
  18.     /* ALWAYS KEEP FormatRevision AS THE FIRST ELEMENT IN THIS RECORD */
  19.     short                    FormatRevision;        /* FIRST ALWAYS, Change each time the format changes */
  20.     WindowLocRec    theWindowLocRec;    /* For saving window positions */
  21.  
  22.     /* Add other preference variable definitions after this line */
  23.  
  24. }PrefsRec,*PrefsPRec,**PrefsHRec;
  25.  
  26. /* ======================================================= */
  27. /* ======================================================= */
  28. $$CloseFile
  29. $$Message User Common, u:common$Prototype.name$.c
  30. $$File u:common$Prototype.name$.c
  31. /*  common$Prototype.name$                         Common */
  32. /*  $CopyRight$ */
  33.  
  34. /* 
  35.     File name:  common$Prototype.name$.c   
  36.     Function:  Common variables for program specific code. 
  37.     History: $Date$ Original by $Author$
  38.  
  39.    */
  40.  
  41.  
  42. #include "mmCommon$Prototype.name$.h"    /* Common */
  43. #include "common$Prototype.name$.h"        /* Common */
  44.  
  45. /* ======================================================= */
  46. /* ======================================================= */
  47.  
  48. #define    PrefsCreator        'xxxx'                /* Creator, this has to be the same as your App */
  49. #define    PrefsType                'Pref'                /* Type, this has to match the type in your BNDL */
  50. #define    PrefsFileName        "\p$Prototype.name$ Prefs"    /* This is the name of your prefs file */
  51.  
  52. #define    PrefsFormatRevision        1                /* Change each time the format changes */
  53.  
  54. /* ======================================================= */
  55.  
  56. /* Routine: U_InitPreferences */
  57. /* Purpose: Set the default preferences */
  58.  
  59. void U_InitPreferences(void)
  60. {
  61.  
  62. }
  63.  
  64. /* ======================================================= */
  65.  
  66. /* Routine: U_GetPrefParams */
  67. /* Purpose: Get the preferences Parameters */
  68.  
  69. void U_GetPrefParams(OSType *PrefCreator,OSType *PrefType,Str255 *thePrefsFilename,long *PrefsRecSize,short *thePrefsFormatRevision)
  70. {
  71.  
  72. *PrefCreator = PrefsCreator;
  73. *PrefType = PrefsType;
  74. PStrCopy((Str255 *)PrefsFileName,thePrefsFilename);
  75. *PrefsRecSize = sizeof(PrefsRec);
  76. *thePrefsFormatRevision = PrefsFormatRevision;
  77. }
  78.  
  79. /* ======================================================= */
  80.  
  81. /* Routine: U_ReadPrefsPrivate */
  82. /* Purpose: Read the prefs ourselves */
  83.  
  84. void U_ReadPrefsPrivate(short PrefsRefNum)
  85. {
  86.  
  87. }
  88.  
  89. /* ======================================================= */
  90.  
  91. /* Routine: U_GetPreferences */
  92. /* Purpose: Get the preferences from the Prefs record already read in */
  93.  
  94. void U_GetPreferences(Handle thePrefsH)
  95. {
  96. PrefsHRec thePrefs;
  97.  
  98.  
  99. thePrefs = (PrefsHRec)thePrefsH;
  100. theWindowLocRec = (*thePrefs)->theWindowLocRec;    /* Get the window location data */
  101.  
  102. /* Use the form:   xxxx = (*thePrefs)->xxxx;    */
  103. }
  104.  
  105. /* ======================================================= */
  106.  
  107. /* Routine: U_SetPreferences */
  108. /* Purpose: Set new preferences, to be written out to the file */
  109.  
  110. void U_SetPreferences(Handle thePrefsH)
  111. {
  112. PrefsHRec thePrefs;
  113.  
  114.  
  115. thePrefs = (PrefsHRec)thePrefsH;
  116. (*thePrefs)->FormatRevision = PrefsFormatRevision;    /* Version number */
  117. (*thePrefs)->theWindowLocRec = theWindowLocRec;        /* Save the window location data */
  118.  
  119. /* Use the form:   (*thePrefs)->xxxx = xxxx;    */
  120. }
  121.  
  122. /* ======================================================= */
  123.  
  124. /* Routine: Close_The_Input_File */
  125. /* Purpose: Close the input file */
  126.  
  127. void Close_The_Input_File(void)
  128. {
  129. OSErr        ErrorCode;
  130.  
  131.  
  132. ErrorCode = FSClose(Files.inputRefNum);                /* Invalidate the refnum */
  133. Files.inputRefNum = 0;                                /* Close the file */
  134. }
  135.  
  136. /* ======================================================= */
  137.  
  138. /* Routine: Close_The_Output_File */
  139. /* Purpose: Close the output file */
  140.  
  141. void Close_The_Output_File(void)
  142. {
  143. OSErr        ErrorCode;
  144.  
  145.  
  146. ErrorCode = FSClose(Files.outputRefNum);            /* Invalidate the refnum */
  147. Files.outputRefNum = 0;                                /* Close the file */
  148. }
  149.  
  150. /* ======================================================= */
  151.  
  152. /* Routine: Open_The_File */
  153. /* Purpose: Open the input file */
  154.  
  155. void Open_The_File(void)
  156. {
  157. short    NumberOfTypes;
  158. short    theVolRefNum;
  159. OSErr    ErrorCode;
  160.  
  161.  
  162. Files.typeList[0] = 'TEXT';                            /* Open TEXT files */
  163. Files.typeList[1] = 'text';                            /* Open other files */
  164. NumberOfTypes = 1;                                    /* Only use first filetype in the list */
  165. if (Do_The_Open_File(NumberOfTypes,&theVolRefNum,nil,nil))/* Try to open the file */
  166.     {
  167.     ErrorCode = FSOpen(Files.inputFileName, Files.Reply.vRefNum, &Files.inputRefNum);/* Open the file */
  168.     
  169.     /* ADD in your code here to read the file */
  170.     
  171.     Close_The_Input_File();                            /* Now close this file */
  172.     }
  173. }
  174.  
  175. /* ======================================================= */
  176.  
  177. /* Routine: Select_Volume */
  178. /* Purpose: Select a volume */
  179.  
  180. void Select_Volume(void)
  181. {
  182. FSSpec    theFile;
  183.  
  184.  
  185. if (Has.NewStdFile)                                    /* Do this if we have new Standard File available */
  186.     {
  187.     if (Do_The_Select_Volume(&theFile))
  188.         {
  189.         }
  190.     }
  191. else
  192.     {
  193.     }
  194. }
  195.  
  196. /* ======================================================= */
  197.  
  198. /* Routine: Save_The_File */
  199. /* Purpose: Save the file */
  200.  
  201. void Save_The_File(void)
  202. {
  203. short    theVolRefNum;
  204. short    theRefNum;
  205.  
  206.  
  207. if (Do_The_Save_File(PrefsCreator, 'TEXT',(Str255 *)"\pSave as:",(Str255 *)"\pUntitled",/* Try to save the file */
  208.     &theVolRefNum,&theRefNum,nil))
  209.     {
  210.  
  211.     /* ADD in your code here to save the file */
  212.  
  213.     Close_The_Output_File();                        /* Now close this file */
  214.     }                                                /* End of IF */
  215. }
  216.  
  217. /* ======================================================= */
  218.  
  219. /* Routine: Print_The_Data */
  220. /* Purpose: Print the data */
  221.  
  222. void Print_The_Data(void)
  223. {
  224. GrafPtr    ThePrintPort;                                /* Print port */
  225. GrafPtr    SavedPort;                                    /* saved window port */
  226. short    Doing_Page;                                    /* Current print page number */
  227. short    NumberOfCopies;                                /* Number of copies of each page */
  228. short    Count;                                        /* Number of copies of each page */
  229. Boolean    Cancelled;                                    /* User cancelled flag */
  230. short    NumberOfPages;                                /* Change this for the number of pages to do */
  231. Str255    ThePageString;                                /* For showing the page number */
  232.  
  233.  
  234. GetPort(&SavedPort);                                /* Get the current window port */
  235.  
  236. NumberOfPages = 2;                                    /* CHANGE for your pages limit */
  237. OpenThePrinter(&Cancelled);                            /* Ask about the next page */
  238.  
  239. if ((Printing.pPrPort != NIL) && (Printing.hPrint != NIL) &&  (!Cancelled))
  240.     {
  241.     ThePrintPort = (GrafPtr)Printing.pPrPort;        /* Get the current window port */
  242.     SetPort(ThePrintPort);                            /* Point to the printer port */
  243.     TextFont(systemFont);
  244.     TextSize(12);
  245.     Doing_Page = 0;
  246.  
  247.     do                                                /* Do all the pages in our document */
  248.         {
  249.         InitCursor();
  250.         Doing_Page = Doing_Page + 1;                /* Bump the page count */
  251.  
  252.         PrOpenPage(Printing.pPrPort, nil);            /* Open a new page */
  253.         SetPort(ThePrintPort);
  254.  
  255.         /* ADD YOUR PRINTING CODE HERE, DRAW INTO THIS PORT */
  256.         MoveTo(10, 20);
  257.         DrawString((StringPtr)"\pPrinting from Gooey¬ code, page ");
  258.         NumToString(Doing_Page,ThePageString);
  259.         DrawString(ThePageString);
  260.         /* END OF ADD YOUR PRINTING CODE HERE */
  261.  
  262.         PrClosePage(Printing.pPrPort);                /* Print this page */
  263.         SetPort(SavedPort);
  264.         }
  265.     while (Doing_Page < NumberOfPages);
  266.     }
  267.  
  268. CloseThePrinter();                                    /* Close the printer */
  269. SetPort(SavedPort);
  270. InitCursor();
  271. }
  272.  
  273. /* ======================================================= */
  274. /* ======================================================= */
  275. $$CloseFile
  276.  
  277.  
  278.